<?php

require_once('./Data.php');
/**
 *
 *
 * @version $Id$
 * @copyright 2007
 */

 class Author extends Data {
 	function __construct(){
 		$options = array(
 			'table' => 'mt_author',
			'columns' => array(
				'id' => 'author_id',
				'name' => 'author_name',
				'nickname' => 'author_nickname',
				'password' => 'author_password',
				'email' => 'author_email',
				'url' => 'author_url',
				'can_create_blog' => 'author_can_create_blog',
				'can_view_log' => 'author_can_view_log',
				'hint' => 'author_hint',
				'created_by' => 'author_created_by',
				'public_key' => 'author_public_key',
				'preferred_language' => 'author_preferred_language',
				'created_on' => 'author_created_on',
				'modified_by' => 'author_modified_by',
				'api_password' => 'author_api_password',
				'remote_auth_token' => 'author_remote_auth_token',
				'remote_auth_username' => 'author_remote_auth_username',
				'is_superuser' => 'author_is_superuser',
				'modified_on' => 'author_modified_on',
				'type' => 'author_type'
			),
			'key' => 'id'
		);
		parent::init($options);
	}
}

class Blog extends Data {
 	function __construct(){
 		$options = array(
 			'table' => 'mt_blog',
			'columns' => array(
				'id' => 'blog_id',
				'name' => 'blog_name',
				'description' => 'blog_description',
				'site_path' => 'blog_site_path',
				'site_url' => 'blog_site_url',
				'archive_path' => 'blog_archive_path',
				'archive_url' => 'blog_archive_url',
				'archive_type' => 'blog_archive_type',
				'archive_type_preferred' => 'blog_archive_type_preferred',
				'days_on_index' => 'blog_days_on_index',
				'language' => 'blog_language',
				'file_extension' => 'blog_file_extension',
				'email_new_comments' => 'blog_email_new_comments',
				'email_new_pings' => 'blog_email_new_pings',
				'allow_comment_html' => 'blog_allow_comment_html',
				'autolink_urls' => 'blog_autolink_urls',
				'sort_order_posts' => 'blog_sort_order_posts',
				'sort_order_comments' => 'blog_sort_order_comments',
				'allow_comments_default' => 'blog_allow_comments_default',
				'allow_pings_default' => 'blog_allow_pings_default',
				'server_offset' => 'blog_server_offset',
				'convert_paras' => 'blog_convert_paras',
				'convert_paras_comments' => 'blog_convert_paras_comments',
				'status_default' => 'blog_status_default',
				'allow_anon_comments' => 'blog_allow_anon_comments',
				'words_in_excerpt' => 'blog_words_in_excerpt',
				'ping_weblogs' => 'blog_ping_weblogs',
				'ping_blogs' => 'blog_ping_blogs',
				'ping_others' => 'blog_ping_others',
				'mt_update_key' => 'blog_mt_update_key',
				'autodiscover_links' => 'blog_autodiscover_links',
				'welcome_msg' => 'blog_welcome_msg',
				'archive_tmpl_monthly' => 'blog_archive_tmpl_monthly',
				'archive_tmpl_weekly' => 'blog_archive_tmpl_weekly',
				'archive_tmpl_daily' => 'blog_archive_tmpl_daily',
				'archive_tmpl_individual' => 'blog_archive_tmpl_individual',
				'archive_tmpl_category' => 'blog_archive_tmpl_category',
				'google_api_key' => 'blog_google_api_key',
				'sanitize_spec' => 'blog_sanitize_spec',
				'cc_license' => 'blog_cc_license',
				'is_dynamic' => 'blog_is_dynamic',
				'allow_unreg_comments' => 'blog_allow_unreg_comments',
				'moderate_pings' => 'blog_moderate_pings',
				'entries_on_index' => 'blog_entries_on_index',
				'remote_auth_token' => 'blog_remote_auth_token',
				'internal_autodiscovery' => 'blog_internal_autodiscovery',
				'ping_technorati' => 'blog_ping_technorati',
				'junk_score_threshold' => 'blog_junk_score_threshold',
				'custom_dynamic_templates' => 'blog_custom_dynamic_templates',
				'junk_folder_expiry' => 'blog_junk_folder_expiry',
				'allow_reg_comments' => 'blog_allow_reg_comments',
				'basename_limit' => 'blog_basename_limit',
				'manual_approve_commenters' => 'blog_manual_approve_commenters',
				'allow_pings' => 'blog_allow_pings',
				'require_comment_emails' => 'blog_require_comment_emails',
				'children_modified_on' => 'blog_children_modified_on',
				'moderate_unreg_comments' => 'blog_moderate_unreg_comments',
				'old_style_archive_links' => 'blog_old_style_archive_links'
			),
			'key' => 'id'
		);
		parent::init($options);
	}

	function entries() {
		$entry = new Entry();
		$entry->blog_id = $this->id;
		return $entry->find();
	}
}

class Category extends Data {
 	function __construct(){
 		$options = array(
 			'table' => 'mt_category',
			'columns' => array(
				'id' => 'category_id',
				'blog_id' => 'category_blog_id',
				'allow_pings' => 'category_allow_pings',
				'label' => 'category_label',
				'description' => 'category_description',
				'author_id' => 'category_author_id',
				'ping_urls' => 'category_ping_urls',
				'parent' => 'category_parent'
			),
			'key' => 'id',
			'pkey' => 'parent'
		);
		parent::init($options);
	}

	function entries(){
		$entry = new Entry();
		$entry->category_id = $this->id;
		return $entry->find();
	}
}

class Comment extends Data {
 	function __construct(){
 		$options = array(
 		 	'table' => 'mt_comment',
			'columns' => array(
				'id' => 'comment_id',
				'blog_id' => 'comment_blog_id',
				'id' => 'comment_entry_id',
				'ip' => 'comment_ip',
				'author' => 'comment_author',
				'email' => 'comment_email',
				'url' => 'comment_url',
				'text' => 'comment_text',
				'created_on' => 'comment_created_on',
				'modified_on' => 'comment_modified_on',
				'created_by' => 'comment_created_by',
				'modified_by' => 'comment_modified_by',
				'commenter_id' => 'comment_commenter_id',
				'junk_score' => 'comment_junk_score',
				'junk_status' => 'comment_junk_status',
				'visible' => 'comment_visible',
				'last_moved_on' => 'comment_last_moved_on',
				'junk_log' => 'comment_junk_log'
			),
			'key' => 'id'
		);
		parent::init($options);
	}
}

class Config extends Data {
 	function __construct(){
 		$options = array(
 		 	'table' => 'mt_config',
			'columns' => array(
				'id' => 'config_id',
				'data' => 'config_data'
			),
			'key' => 'id'
		);
		parent::init($options);
	}
}

class Entry extends Data {
 	function __construct(){
 		$options = array(
 		 	'table' => 'mt_entry',
			'columns' => array(
				'id' => 'entry_id',
				'blog_id' => 'entry_blog_id',
				'status' => 'entry_status',
				'author_id' => 'entry_author_id',
				'allow_comments' => 'entry_allow_comments',
				'allow_pings' => 'entry_allow_pings',
				'convert_breaks' => 'entry_convert_breaks',
				'category_id' => 'entry_category_id',
				'title' => 'entry_title',
				'excerpt' => 'entry_excerpt',
				'text' => 'entry_text',
				'text_more' => 'entry_text_more',
				'to_ping_urls' => 'entry_to_ping_urls',
				'pinged_urls' => 'entry_pinged_urls',
				'keywords' => 'entry_keywords',
				'tangent_cache' => 'entry_tangent_cache',
				'created_on' => 'entry_created_on',
				'modified_on' => 'entry_modified_on',
				'created_by' => 'entry_created_by',
				'modified_by' => 'entry_modified_by',
				'atom_id' => 'entry_atom_id',
				'basename' => 'entry_basename',
				'week_number' => 'entry_week_number'
			),
			'key' => 'id'
		);
		parent::init($options);
	}


	function comments() {
		$comment = new Comment();
		$comment->entry_id = $this->id;
		return $comment->find();
	}
}

class FileInfo extends Data {
 	function __construct(){
 		$options = array(
 		 	'table' => 'mt_fileinfo',
			'columns' => array(
				'id' => 'fileinfo_id',
				'archive_type' => 'fileinfo_archive_type',
				'blog_id' => 'fileinfo_blog_id',
				'category_id' => 'fileinfo_category_id',
				'entry_id' => 'fileinfo_entry_id',
				'file_path' => 'fileinfo_file_path',
				'startdate' => 'fileinfo_startdate',
				'id' => 'fileinfo_template_id',
				'id' => 'fileinfo_templatemap_id',
				'url' => 'fileinfo_url',
				'virtual' => 'fileinfo_virtual'
			),
			'key' => 'id'
		);
		parent::init($options);
	}
}

class IpBanList extends Data {
 	function __construct(){
 		$options = array(
 		 	'table' => 'mt_ipbanlist',
			'columns' => array(
				'id' => 'ipbanlist_id',
				'blog_id' => 'ipbanlist_blog_id',
				'ip' => 'ipbanlist_ip',
				'created_on' => 'ipbanlist_created_on',
				'modified_on' => 'ipbanlist_modified_on',
				'created_by' => 'ipbanlist_created_by',
				'modified_by' => 'ipbanlist_modified_by'
			),
			'key' => 'id'
		);
		parent::init($options);
	}
}

class Log extends Data {
 	function __construct(){
 		$options = array(
 		 	'table' => 'mt_log',
			'columns' => array(
				'id' => 'log_id',
				'message' => 'log_message',
				'ip' => 'log_ip',
				'created_on' => 'log_created_on',
				'modified_on' => 'log_modified_on',
				'created_by' => 'log_created_by',
				'modified_by' => 'log_modified_by',
				'blog_id' => 'log_blog_id'
			),
			'key' => 'id'
		);
		parent::init($options);
	}
}

class Notification extends Data {
 	function __construct(){
 		$options = array(
 		 	'table' => 'mt_notification',
			'columns' => array(
				'id' => 'notification_id',
				'blog_id' => 'notification_blog_id',
				'name' => 'notification_name',
				'email' => 'notification_email',
				'url' => 'notification_url',
				'created_on' => 'notification_created_on',
				'modified_on' => 'notification_modified_on',
				'created_by' => 'notification_created_by',
				'modified_by' => 'notification_modified_by'
			),
			'key' => 'id'
		);
		parent::init($options);
	}
}

class NotifierData extends Data {
 	function __construct(){
 		$options = array(
 		 	'table' => 'mt_notifier_data',
			'columns' => array(
				'id' => 'notifier_data_id',
				'blog_id' => 'notifier_data_blog_id',
				'category_id' => 'notifier_data_category_id',
				'entry_id' => 'notifier_data_entry_id',
				'email' => 'notifier_data_email',
				'cipher' => 'notifier_data_cipher',
				'record' => 'notifier_data_record',
				'status' => 'notifier_data_status'
			),
			'key' => 'id'
		);
		parent::init($options);
	}
}

class NotifierQueue extends Data {
 	function __construct(){
 		$options = array(
 		 	'table' => 'mt_notifier_queue',
			'columns' => array(
				'_id' => 'notifier_queue_id',
				'_head_content' => 'notifier_queue_head_content',
				'_head_from' => 'notifier_queue_head_from',
				'_head_to' => 'notifier_queue_head_to',
				'_head_subject' => 'notifier_queue_head_subject',
				'_body' => 'notifier_queue_body'
			),
			'key' => 'id'
		);
		parent::init($options);
	}
}

class Permission extends Data {
 	function __construct(){
 		$options = array(
 		 	'table' => 'mt_permission',
			'columns' => array(
				'id' => 'permission_id',
				'author_id' => 'permission_author_id',
				'blog_id' => 'permission_blog_id',
				'role_mask' => 'permission_role_mask',
				'entry_prefs' => 'permission_entry_prefs'
			),
			'key' => 'id'
		);
		parent::init($options);
	}
}

class Placement extends Data {
 	function __construct(){
 		$options = array(
 		 	'table' => 'mt_placement',
			'columns' => array(
				'id' => 'placement_id',
				'entry_id' => 'placement_entry_id',
				'blog_id' => 'placement_blog_id',
				'category_id' => 'placement_category_id',
				'is_primary' => 'placement_is_primary'
			),
			'key' => 'id'
		);
		parent::init($options);
	}
}

class PluginData extends Data {
 	function __construct(){
 		$options = array(
 		 	'table' => 'mt_plugindata',
			'columns' => array(
				'id' => 'plugindata_id',
				'plugin' => 'plugindata_plugin',
				'key' => 'plugindata_key',
				'data' => 'plugindata_data'
			),
			'key' => 'id'
		);
		parent::init($options);
	}
}

class Session extends Data {
 	function __construct(){
 		$options = array(
 		 	'table' => 'mt_session',
			'columns' => array(
				'data' => 'session_data',
				'email' => 'session_email',
				'id' => 'session_id',
				'kind' => 'session_kind',
				'name' => 'session_name',
				'start' => 'session_start'
			),
			'key' => 'id'
		);
		parent::init($options);
	}
}

class TbPing extends Data {
 	function __construct(){
 		$options = array(
 		 	'table' => 'mt_tbping',
			'columns' => array(
				'id' => 'tbping_id',
				'blog_id' => 'tbping_blog_id',
				'tb_id' => 'tbping_tb_id',
				'title' => 'tbping_title',
				'excerpt' => 'tbping_excerpt',
				'source_url' => 'tbping_source_url',
				'ip' => 'tbping_ip',
				'blog_name' => 'tbping_blog_name',
				'created_on' => 'tbping_created_on',
				'modified_on' => 'tbping_modified_on',
				'created_by' => 'tbping_created_by',
				'modified_by' => 'tbping_modified_by',
				'junk_score' => 'tbping_junk_score',
				'junk_status' => 'tbping_junk_status',
				'visible' => 'tbping_visible',
				'last_moved_on' => 'tbping_last_moved_on',
				'junk_log' => 'tbping_junk_log'
			),
			'key' => 'id'
		);
		parent::init($options);
	}
}

class Template extends Data {
 	function __construct(){
 		$options = array(
 		 	'table' => 'mt_template',
			'columns' => array(
				'id' => 'template_id',
				'blog_id' => 'template_blog_id',
				'name' => 'template_name',
				'type' => 'template_type',
				'outfile' => 'template_outfile',
				'rebuild_me' => 'template_rebuild_me',
				'text' => 'template_text',
				'linked_file' => 'template_linked_file',
				'linked_file_mtime' => 'template_linked_file_mtime',
				'linked_file_size' => 'template_linked_file_size',
				'build_dynamic' => 'template_build_dynamic',
				'modified_on' => 'template_modified_on',
				'created_on' => 'template_created_on',
				'modified_by' => 'template_modified_by',
				'created_by' => 'template_created_by'
			),
			'key' => 'id'
		);
		parent::init($options);
	}

	private $map = array();

	function assign($prefix, $value){
		if(is_object($value)) {
			foreach($value as $k => $v) {
				$k = ucfirst($k);
				$this->map["<{$prefix}{$k}>"] = $v;
			}
		}else
			$this->map["$prefix"] = $value;
	}

	function __toString(){
		$template = strtr($this->text, array('<$' => '<', '$>' => '>'));
		return strtr($template, $this->map);
	}
}

class TemplateMap extends Data {
 	function __construct(){
 		$options = array(
 		 	'table' => 'mt_templatemap',
			'columns' => array(
				'id' => 'templatemap_id',
				'blog_id' => 'templatemap_blog_id',
				'id' => 'templatemap_template_id',
				'archive_type' => 'templatemap_archive_type',
				'file_template' => 'templatemap_file_template',
				'is_preferred' => 'templatemap_is_preferred'
			),
			'key' => 'id'
		);
		parent::init($options);
	}
}

class TrackBack extends Data {
 	function __construct(){
 		$options = array(
 		 	'table' => 'mt_trackback',
			'columns' => array(
				'id' => 'trackback_id',
				'blog_id' => 'trackback_blog_id',
				'title' => 'trackback_title',
				'description' => 'trackback_description',
				'rss_file' => 'trackback_rss_file',
				'url' => 'trackback_url',
				'entry_id' => 'trackback_entry_id',
				'category_id' => 'trackback_category_id',
				'passphrase' => 'trackback_passphrase',
				'is_disabled' => 'trackback_is_disabled',
				'created_on' => 'trackback_created_on',
				'modified_on' => 'trackback_modified_on',
				'created_by' => 'trackback_created_by',
				'modified_by' => 'trackback_modified_by'
			),
			'key' => 'id'
		);
		parent::init($options);
	}
}

?>